import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Arrays;
public class Jianqie {
    public static void main(String[] args) throws Exception{
        shearing("D:/p1","D:\\p2");
    }
    public static void shearing(String source,String goal) throws Exception{
        File fileSource=new File(source);
        if(!fileSource.exists()){
            throw new NullPointerException("文件不存在");
        }
        if(fileSource.isFile()){
            File fileGoal=new File(goal,fileSource.getName());
            FileInputStream fin = new FileInputStream(fileSource);
            System.out.println();
            FileOutputStream fos = new FileOutputStream(fileGoal);
            int n;
            while((n=fin.read())!=-1){
                fos.write(n);
            }
            fos.flush();
            fos.close();
            fin.close();
            fileSource.delete();
            return ;
        }
        File fileGoal=new File(goal,fileSource.getName());
        fileGoal.mkdir();
        File[] listFiles = fileSource.listFiles();
        assert listFiles != null;
        for (File listFile : listFiles) {
            String aa = listFile.getAbsolutePath();
            String bb = fileGoal.getAbsolutePath();
            System.out.println(aa + "----" + bb);
            shearing(listFile.getAbsolutePath(), fileGoal.getAbsolutePath());
        }
        fileSource.delete();
    }
}